package com.desmart.renjiao.main.mine;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Base64;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.desmart.renjiao.R;
import com.desmart.renjiao.bean.LoginBean;
import com.lemon.library.constants.PreferencesConstants;
import com.google.gson.Gson;
import com.lemon.library.common.ARoutePath;
import com.lemon.library.common.CommonFragment;
import com.lemon.library.utils.PreferencesUtils;

@Route(path = ARoutePath.Main.MineFragment)
public class MineFragment extends CommonFragment implements View.OnClickListener {

    private TextView tvName;
    private TextView tvDepartMent;
    private TextView tvCommpany;
    private ImageView ivHead;

    @Override
    public int bindLayout() {
        return R.layout.fragment_main_mine;
    }

    @Override
    public void initView(View view) {
        view.findViewById(R.id.tv_user_info).setOnClickListener(this);
        view.findViewById(R.id.tv_change_pwd).setOnClickListener(this);

        tvName = view.findViewById(R.id.tv_name);
        tvDepartMent = view.findViewById(R.id.tv_department);
        tvCommpany = view.findViewById(R.id.tv_company);
        ivHead = view.findViewById(R.id.iv_head);
    }

    @Override
    public void initData() {

        String loginInfoStr = PreferencesUtils.getString(PreferencesConstants.login_info);
        if (loginInfoStr != null){
            LoginBean loginBean = new Gson().fromJson(loginInfoStr, LoginBean.class);

            tvName.setText(loginBean.getName());
            tvDepartMent.setText(loginBean.getDepartmentdesc());
            tvCommpany.setText(loginBean.getCompanyname());
            ivHead.setImageBitmap(stringtoBitmap(loginBean.getPho()));
        }

    }

    public Bitmap stringtoBitmap(String string){
        Bitmap bitmap=null;
        try {
            byte[]bitmapArray;
            bitmapArray=Base64.decode(string, Base64.DEFAULT);
            bitmap=BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return bitmap;
    }

    @Override
    public void onClick(View v) {

    }
}
